package com.example.demo.core.service;

import com.example.demo.core.entity.RoleMenu;
import com.example.demo.core.repository.RoleMenuRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


@Service
public class RoleMenuService {

    @Autowired
    private RoleMenuRepository roleMenuRepository;

    /**
    * @Description: 添加RoleMenu实体
    * @Param:  roleID: 角色ID
     * @Param: menuID: 菜单ID
    * @return:  RoleMenu
    * @Author: wangze
    */
    public RoleMenu addRoleMenu(Integer roleId,Integer menuId){
        RoleMenu roleMenu=new RoleMenu();
        roleMenu.setRoleId(roleId);
        roleMenu.setMenuId(menuId);
        return roleMenuRepository.save(roleMenu);
    }

    /**
     * @Description: 根据角色ID删除对应角色的所有菜单
     * @Param:  roleID: 角色ID
     * @return:
     * @Author: wangze
     */
    @Transactional
    public void removeMenuByRoleId(Integer roleId) {
        roleMenuRepository.deleteAllByRoleId(roleId);
    }

}
